const db = uniCloud.database();
const selfUtils = require('self-utils')
module.exports = {
  _before: function() { // 通用预处理器
    this.params = this.getParams()[0]
    //if (!this.userInfo.uid) throw this.userInfo;
  },
  async get() {
    return await db.collection("ly-mall-brand").get()
  },
  async add() {
    //判断是否为管理员
    if (!this.userInfo.role.includes('manage')) {
      return {
        msg: '没有操作权限',
        code: -1
      }
    }
    return await db.collection("ly-mall-brand").add(this.params)
  },
  async update() {
    //判断是否为管理员
    if (!this.userInfo.role.includes('manage')) {
      return {
        msg: '没有操作权限',
        code: -1
      }
    }
    let params = {
      ...this.params
    };
    delete params._id
    return await db.collection("ly-mall-brand").doc(this.params._id).update(params)
  },
}